/*
 * By Marcus Fazzi (Anunakin@ieee.org) GPLv2
 * http://fazzi.eng.br
 * 
 * Integer sin() and cos(), in name of memory! :)
 */

//Integer sins => (sin(x*0.1045))
#ifndef INTEGER_MATH_h
#define INTEGER_MATH_h

#ifndef USE_INTEGER_RETURN

typedef float returntype;

const float sins[] = { 0,0.0174524064,0.0348994967,0.0523359562,0.0697564737,
0.0871557427,0.1045284633,0.1218693434,0.139173101,0.156434465,0.1736481777,
0.1908089954,0.2079116908,0.2249510543,0.2419218956,0.2588190451,0.2756373558,
0.2923717047,0.3090169944,0.3255681545,0.3420201433,0.3583679495,0.3746065934,
0.3907311285,0.4067366431,0.4226182617,0.4383711468,0.4539904997,0.4694715628,
0.4848096202,0.5,0.5150380749,0.5299192642,0.544639035,0.5591929035,0.5735764364,
0.5877852523,0.6018150232,0.6156614753,0.629320391,0.6427876097,0.656059029,
0.6691306064,0.6819983601,0.6946583705,0.7071067812,0.7193398003,0.7313537016,
0.7431448255,0.7547095802,0.7660444431,0.7771459615,0.7880107536,0.79863551,
0.8090169944,0.8191520443,0.8290375726,0.8386705679,0.8480480962,0.8571673007,
0.8660254038,0.8746197071,0.8829475929,0.8910065242,0.8987940463,0.906307787,
0.9135454576,0.9205048535,0.9271838546,0.9335804265,0.9396926208,0.9455185756,
0.9510565163,0.956304756,0.9612616959,0.9659258263,0.9702957263,0.9743700648,
0.9781476007,0.9816271834,0.984807753,0.9876883406,0.9902680687,0.9925461516,
0.9945218954,0.9961946981,0.9975640503,0.9986295348,0.999390827,0.9998476952,
1 };
#else
/*TODO Aplicar deslocamento de bits */
typedef unsigned int returntype;

const unsigned int sins[] = { 0,
17452,34899,52335,69756,87155,104528,121869,13917,15643,173648,190808,
207911,224951,241921,258819,275637,292371,309016,325568,342020,358367,
374606,390731,406736,422618,438371,453990,469471,484809,500000,515038,
529919,544639,559192,573576,587785,601815,615661,629320,642787,656059,
669130,681998,694658,707106,719339,731353,743144,754709,766044,777145,
788010,798635,809016,819152,829037,838670,848048,857167,866025,874619,
882947,891006,898794,906307,913545,920504,927183,933580,939692,945518,
951056,956304,961261,965925,970295,974370,978147,981627,984807,987688,
990268,992546,994521,996194,997564,998629,999390,999847,1000000 };
#endif

returntype sini(unsigned int x);
returntype cosi(unsigned int x);
returntype tani(unsigned int x);
returntype powi(int base, int num);

#endif
